using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MAPDavy.Entities;

namespace MAPDavy.Repository.Mapping
{
	public class TestGradeMap : EntityTypeConfiguration<TestGrade>
	{
		public TestGradeMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.Anio)
				.IsRequired()
				.IsFixedLength()
				.HasMaxLength(4);
				
			// Table & Column Mappings
			this.ToTable("TestGrade");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.TestId).HasColumnName("TestId");
			this.Property(t => t.GradeId).HasColumnName("GradeId");
			this.Property(t => t.Anio).HasColumnName("Anio");

			// Relationships
            this.HasRequired(t => t.Term)
                .WithMany(t => t.TestGrades)
                .HasForeignKey(d => d.TermId);
				
			this.HasRequired(t => t.Grade)
				.WithMany(t => t.TestGrades)
				.HasForeignKey(d => d.GradeId);
				
			this.HasRequired(t => t.Test)
				.WithMany(t => t.TestGrades)
				.HasForeignKey(d => d.TestId);
				
		}
	}
}

